package com.clone.surpassli.clone_cloudreader.ui;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.bumptech.glide.Glide;
import com.clone.surpassli.clone_cloudreader.MainActivity;
import com.clone.surpassli.clone_cloudreader.R;
import com.clone.surpassli.clone_cloudreader.app.ConstantsImageUrl;
import com.clone.surpassli.clone_cloudreader.databinding.ActivityTransitionBinding;
import com.clone.surpassli.clone_cloudreader.utils.CommonUtils;

import java.util.Random;

/**
 * Created by SurpassLi on 2017/10/18.
 * TransitionActivity
 */

public class TransitionActivity extends AppCompatActivity {
    ActivityTransitionBinding binding;
    private boolean animationEnd;
    private boolean isIn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_transition);
        int i = new Random().nextInt(ConstantsImageUrl.TRANSITION_URLS.length);
        //先显示默认图
        binding.ivDefaultPic.setImageDrawable(CommonUtils.getDrawable(R.drawable.img_transition_default));
        Glide.with(this)
                .load(ConstantsImageUrl.TRANSITION_URLS[i])
                .placeholder(R.drawable.img_transition_default)
                .error(R.drawable.img_transition_default)
                .into(binding.ivPic);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                binding.ivDefaultPic.setVisibility(View.GONE);
            }
        }, 1500);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                toMainActivity();
            }
        }, 3500);
    }

    private void toMainActivity() {
        if (isIn) {
            return;
        }
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.screen_zoom_in, R.anim.screen_zoom_out);
        finish();
        isIn = true;
    }
}
